package qf.sail.entity;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

public class Order extends BaseEntity{
    private String sn;  //订单号

    private String status;  //订单状态

    private BigDecimal totalFreight = new BigDecimal(0);    //运费

    private BigDecimal payMoney;    //支付金额

    private int number;     //商品数量

    private String address;     //收货地址

    private Long accountId;     //用户id

    private List<OrderItem> orderItemList;      //订单子项

    private String orderTime;   //下单时间

    private String payTime;     //支付时间

    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public BigDecimal getTotalFreight() {
        return totalFreight;
    }

    public void setTotalFreight(BigDecimal totalFreight) {
        this.totalFreight = totalFreight;
    }

    public BigDecimal getPayMoney() {
        return payMoney;
    }

    public void setPayMoney(BigDecimal payMoney) {
        this.payMoney = payMoney;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Long getAccountId() {
        return accountId;
    }

    public void setAccountId(Long accountId) {
        this.accountId = accountId;
    }

    public List<OrderItem> getOrderItemList() {
        return orderItemList;
    }

    public void setOrderItemList(List<OrderItem> orderItemList) {
        this.orderItemList = orderItemList;
    }

    public String getOrderTime() {
        return orderTime;
    }

    public void setOrderTime(String orderTime) {
        this.orderTime = orderTime;
    }

    public String getPayTime() {
        return payTime;
    }

    public void setPayTime(String payTime) {
        this.payTime = payTime;
    }

    @Override
    public void setCreateTime(Timestamp createTime) {
        super.setCreateTime(createTime);
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        this.orderTime = sdf.format(createTime);
    }

    @Override
    public void setUpdateTime(Timestamp updateTime) {
        if(updateTime != null) {
            super.setUpdateTime(updateTime);
            DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            this.payTime = sdf.format(updateTime);
        }
    }

    @Override
    public String toString() {
        return "Order{" +
                "sn='" + sn + '\'' +
                ", status='" + status + '\'' +
                ", totalFreight=" + totalFreight +
                ", payMoney=" + payMoney +
                ", number=" + number +
                ", address='" + address + '\'' +
                ", accountId=" + accountId +
                ", orderItemList=" + orderItemList +
                ", orderTime='" + orderTime + '\'' +
                ", payTime='" + payTime + '\'' +
                '}';
    }
}
